package it.flavio.converter.tools;

import java.io.IOException;
import java.net.MalformedURLException;

import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;

public class FinanceTools {

	private static final String YAHOO_FINANCE_API = "http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote";
	
	public static void main(String[] args) throws MalformedURLException, IOException {
//		updateCurrencies();
	}
	
	
	//http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote
	//http://www.mkyong.com/java/how-to-read-xml-file-in-java-sax-parser/
	//http://en.wikipedia.org/wiki/Java_API_for_XML_Processing
	public static void updateCurrencies() throws MalformedURLException, IOException {
		
//		HttpURLConnection yahooHttpConn= (HttpURLConnection) (new URL(YAHOO_FINANCE_API)).openConnection();
//		yahooHttpConn.connect();

		/*
		URL url = new URL(YAHOO_FINANCE_API);
        //String query = INSERT_HERE_YOUR_URL_PARAMETERS;

        //make connection
        URLConnection urlc = url.openConnection();

        //use post mode
        urlc.setDoOutput(true);
        urlc.setAllowUserInteraction(false);

        //send query
        PrintStream ps = new PrintStream(urlc.getOutputStream());
        ps.print("");
        ps.close();

        //get result
        BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
        String l = null;
        while ((l=br.readLine())!=null) {
            System.out.println(l);
        }
        br.close();
		*/
		
		HttpClient client = new DefaultHttpClient();
	    HttpGet get = new HttpGet(YAHOO_FINANCE_API);
	    ResponseHandler<String> handler = new BasicResponseHandler();
	    String resp = client.execute(get, handler);

	    System.out.println(resp);
		
	}
	
}
